<!doctype html>

<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<?php
include_once('navbar.php');
include_once('superheader.php');
$username = $_SESSION['username'];
?>

<script>
$(function() {
	
	$( "#subset" ).buttonset();
	
	$("#response").html("");
	$("#response2").html("");
        
        
        var username = "<?php echo $_SESSION['username']; ?>"


          var params =  {
          colReq2: "requests",
          user: username,

        };

        var data = JSON.stringify(params);
        
	
        $.ajax({
                    cache: false,
                    type: "json",
                    url: "/phpfunctions/lists/listWithRecieverParam.php",
                    contentType: "application/json",
                    processData: true,
                    data: data,
                    success: function(res, textStatus, jqXHR){
		      var container = $("#response");
			 var table = $("<table border=\"1\">");
			 var head = $("<tr>");
			 //head.append("<th>MongoId</th>");
			 head.append("<th></th>");
			 head.append("<th>Ticket Num</th>");
			 head.append("<th>Description</th>");
		 	 table.append(head);

			 for(var key in res.data.messages)
			 {
				var tr = $("<tr>");
				var message = res.data.messages[key];
				/*td.html(message['_id']);
				tr.append(td);*/
				
				td = $("<td>");
				var link = $("<a href=\"editRequest.php?requestnum="+message.ticketNum+"\">Modify</a>")
				td.append(link)
				tr.append(td);
				
				var td = $("<td>");
				td.html(message.ticketNum);
				tr.append(td);
					
				td = $("<td>");
				td.html(message.mDescription);
				tr.append(td);

				table.append(tr);			
			 }
                         //container.append(JSON.stringify(res['data']));
			container.html(table);
                    },
                    complete: function(XMLHttpRequest, text_status) {

                    }
                  });
                  
                  
                  
                  $.ajax({
                    cache: false,
                    type: "json",
                    url: "/phpfunctions/lists/listWithGeneratorParam.php",
                    contentType: "application/json",
                    processData: true,
                    data: data,
                    success: function(res, textStatus, jqXHR){
		      var container = $("#response2");
			 var table = $("<table border=\"1\">");
			 var head = $("<tr>");
			 //head.append("<th>MongoId</th>");
			 head.append("<th></th>");
			 head.append("<th>Ticket Num</th>");
			 head.append("<th>Description</th>");
		 	 table.append(head);

			 for(var key in res.data.messages)
			 {
				var tr = $("<tr>");
				var message = res.data.messages[key];
				/*td.html(message['_id']);
				tr.append(td);*/
					
				td = $("<td>");
				var link = $("<a href=\"editRequest.php?requestnum="+message.ticketNum+"\">Modify</a>")
				td.append(link)
				tr.append(td);
				
				var td = $("<td>");
				td.html(message.ticketNum);
				tr.append(td);
					
				td = $("<td>");
				td.html(message.mDescription);
				tr.append(td);

				table.append(tr);			
			 }
                         //container.append(JSON.stringify(res['data']));
			container.html(table);
                    },
                    complete: function(XMLHttpRequest, text_status) {

                    }
                  });
                  
                  
	
});
</script>

</head>

<body>
	<?php
		//$username = $_SESSION['username'];
		$role = $_SESSION['role'];
		echo("<h2>Welcome, ");
		echo($username);
		echo("!</h2>");
	?>

<!--
<form>
	<div id="subset">
		<input type="radio" id="add" name="radio2"><label for="add">add</label>
		<input type="radio" id="remove" name="radio2" checked="checked"><label for="remove">remove</label>
		<?php if($_SESSION['role'] === "admin") : ?>
		<html> <input type="radio" id="something else" name="radio2"><label for="something else">Something Else</label> </html>
		<?php endif; ?>
	</div>
</form>
-->

	<p>The following tickets assigned to you are outstanding:</p>
	<div id="response" style="position: relative; top:10px; left:10px; height:100px">
      Stuff to be replaced
    </div>
    
    
    	<p>Tickets you have created:</p>
	<div id="response2" style="position: relative; top:10px; left:10px; height:100px">
      Stuff to be replaced
    </div>

</body>


</html>


<?php
$username = $_SESSION['username'];
$role = $_SESSION['role'];
?>